<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>借款申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../layui-v2.9.8/layui/css/layui.css">
    <script src="../layui-v2.9.8/layui/layui.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>借款申请</legend>
</fieldset>
<div>
    <form class="layui-form" action="/process/loanadd" enctype="multipart/form-data" method="post" id="loanForm">
        <div style="display: none"><input type="text"name="id"id="formid" th:value="${id}"></div>
        <div class="layui-row">
            <div class="layui-col-xs1"style="text-align: center;height: 38px;font-size: 16px;line-height: 38px">
                <div>借款部门</div>
            </div>
            <div class="layui-col-xs5">
                <input th:value="${department}" name="loanDepartment" id="loanDepartment" type="text" class="layui-input" readonly="readonly" >
            </div>
            <div class="layui-col-xs1"style="text-align: center;height: 38px;font-size: 16px;line-height: 38px">
                <div>借款人</div>
            </div>
            <div class="layui-col-xs5 headfont">
                <input th:value="${userDetails.realName}" name="loanPerson" type="text" class="layui-input" readonly="readonly" >
            </div>
            <div class="layui-col-xs12"style="text-align: center;height: 10px;"></div>
            <div class="layui-col-xs1"style="text-align: center;height: 38px;font-size: 16px;line-height: 38px;">
                <div>借款原因</div>
            </div>
            <div class="layui-col-xs5">
                <textarea name="loanReason"id="loanReason"  class="layui-textarea" lay-verify="required"></textarea>
            </div>
            <div class="layui-col-xs1" style="text-align: center;height: 38px;font-size: 16px;line-height: 38px;">
                <div>借款金额</div>
            </div>
            <div class="layui-col-xs5">
                <input class="layui-input" name="loanAmount" lay-verify="required||isAllDigits"   autocomplete="off"  lay-affix="clear" >
            </div>
            <div class="layui-col-xs12"style="text-align: center;height: 10px;"></div>
            <div class="layui-col-xs1" style="text-align: center;height: 38px;font-size: 16px;line-height: 38px;">
                <div >审核人</div>
            </div>
            <div class="layui-col-xs5">
                <select id="auditingPerson" name="auditingPerson" lay-verify="required">
                    <option value=""></option>
                    <option th:each="BaseUser : ${lb}" th:value="${BaseUser.username}" th:text="${BaseUser.realName}"></option>
                </select>
            </div>
            <div class="layui-col-xs12"style="text-align: center;height: 10px;"></div>
        </div>
        <div style="display: flex;margin-left: 10px;margin-top: 15px">
            <button class="layui-btn"lay-submit lay-filter="submitForm">立即提交</button>
        </div>
    </form>

</div>
<script>
    function deleteprocess() {
        // 创建表单数据对象
        var formData = new FormData();
        formData.append("id", layui.$("#formid").val());
        // 使用sendBeacon方法发送异步请求
        navigator.sendBeacon("/process/delete", formData);
    }
    layui.use(function(){
        var  $=layui.$;
        var form = layui.form;
        var xm
        var keys=[]
        window.addEventListener("beforeunload",deleteprocess);
        var laydate = layui.laydate;
        form.on('submit(submitForm)', function(data){
            var sindex=layer.load(2, {shade: [0.5,'#000']});
            window.removeEventListener("beforeunload",deleteprocess);
            // 手动触发表单的提交
            return true; // 返回 true 表示继续提交表单，返回 false 表示取消提交
        });
        form.verify({
            isAllDigits:function(value){
                if(!/^\d+(\.\d+)?$/.test(value)){
                    return '请输入数字';
                }
            },

        });

    });
</script>
</body>
</html>